<template>
	<view class="white_day ani_move_in">
		<view class="life_title">晨之曦</view>
		<view class="life_one">从有生之年到一息尚存，我当尽力使有限向无限延伸。</view>
		<view class="life_card">
			<view class="watch">
				<view class="face">
					<view class="numbers">
						<view class="number number-1"><span>1</span></view>
						<view class="number number-2"><span>2</span></view>
						<view class="number number-3"><span>3</span></view>
						<view class="number number-4"><span>4</span></view>
						<view class="number number-5"><span>5</span></view>
						<view class="number number-6"><span>6</span></view>
						<view class="number number-7"><span>7</span></view>
						<view class="number number-8"><span>8</span></view>
						<view class="number number-9"><span>9</span></view>
						<view class="number number-10"><span>10</span></view>
						<view class="number number-11"><span>11</span></view>
						<view class="number number-12"><span>12</span></view>
					</view>
					<view class="arms">
						<view class="arm arm-hour" :style="{transform: 'rotateZ('+hourDeg+'deg)'}"></view>
						<view class="arm arm-minute" :style="{transform: 'rotateZ('+minuteDeg+'deg)'}"></view>
						<view class="arm arm-second" :style="{transform: 'rotateZ('+secondDeg+'deg)'}"></view>
					</view>
				</view>
			</view>
			<view class="info">
				<view class="life_time">你已经 {{lifeTime}} 岁了</view>
				<text class="life_tip">在这个世界上，你已经存在</text>
				<view class="row">
					<view class="row_item">
						<view>{{lifeYear}}</view>
						<view>年</view>
					</view>
					<view class="row_item">
						<view>{{lifeMonth | fixedTime}}</view>
						<view>月</view>
					</view>
					<view class="row_item">
						<view>{{lifeWeak | fixedTime}}</view>
						<view>周</view>
					</view>
				</view>
				<view class="row">
					<view class="row_item">
						<view>{{lifeDay | fixedTime}}</view>
						<view>天</view>
					</view>
					<view class="row_item">
						<view>{{lifeHours | fixedTime}}</view>
						<view>小时</view>
					</view>
					<view class="row_item">
						<view>{{lifeMinute | fixedTime}}</view>
						<view>分</view>
					</view>
				</view>
			</view>
			<view class="life_btn" @click="handleOpenBlack">暮之霭</view>
			<u-top-tips ref="uTips"></u-top-tips>
		</view>
	</view>
</template>

<script>
	import {
		getBirthTime,
		getLifeTime
	} from '../utils.js'
	export default {
		data() {
			return {
				hourDeg: 0,
				minuteDeg: 0,
				secondDeg: 0,
				timer: null, // 时间的计时器
				lifeTime: 0,
				lifeMonth: 0,
				lifeWeak: 0,
				lifeDay: 0,
				lifeHours: 0,
				lifeMinute: 0,
				lifeYear: 0,
				birthDate: undefined
			};
		},
		methods: {
			setLifeTime(isUpdate = true, nowDate = new Date(), birthDate) {
				const res = getLifeTime(nowDate, birthDate, isUpdate);
				if (isUpdate) {
					this.lifeMonth = res.lifeMonth;
					this.lifeWeak = res.lifeWeak;
					this.lifeDay = res.lifeDay;
					this.lifeHours = res.lifeHours;
					this.lifeMinute = res.lifeMinute;
					this.lifeYear = res.lifeYear;
				}
				this.lifeTime = res.lifeTime.toFixed(8);
			},
			updateEvent(birthDate) {
				const date = new Date();
				const hour = date.getHours() % 12;
				const minute = date.getMinutes()
				const second = date.getSeconds();
				this.hourDeg = hour * 30;
				this.minuteDeg = minute * 6;
				this.secondDeg = second * 6;
				if (second === 0) {
					this.setLifeTime(true, date, birthDate)
				} else {
					this.setLifeTime(false, date, birthDate)
				}
			},
			handleOpenBlack() {
				this.$emit("type", 2)
			}
		},
		filters: {
			fixedTime(val = 0) {
				return Math.floor(val)
			}
		},
		created() {
			getBirthTime().then(res => {
				const birthDate = new Date(res)
				this.setLifeTime(true, undefined, birthDate)
				this.timer = setInterval(() => {
					this.updateEvent(birthDate)
				}, 1000)
			}, err => {
				uni.navigateTo({
					url: "TimeSetting/TimeSetting"
				})
			})
		},
		beforeDestroy() {
			clearInterval(this.timer)
		}
	}
</script>

<style lang="scss" scoped>
	.white_day {
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.life_title {
		text-align: center;
		font-size: 40rpx;
		font-weight: bold;
		margin-bottom: 20rpx;
	}

	.life_one {
		text-align: center;
		line-height: 50rpx;
	}

	.life_btn {
		position: relative;
		top: 90rpx;
		left: 0;
		right: 0;
		display: block;
		font-size: 34rpx;
		letter-spacing: 6rpx;
		width: 190rpx;
		line-height: 70rpx;
		text-align: center;
		border: 2rpx solid #878787;
		margin: 0 auto;
	}

	.info {
		width: 84%;
		margin: 0 auto;
		margin-top: 40rpx;
		.life_time {
			display: flex;
			justify-content: center;
			text-align: center;
			font-size: 38rpx;
			margin-bottom: 40rpx;
			font-weight: bold;

			.roll_text {
				margin: 0 10rpx;
			}
		}

		.life_tip {
			display: block;
			font-size: 26rpx;
			color: #aaa;
			margin-bottom: 20rpx;
		}

		.row {
			display: flex;
			height: 100rpx;
			border: 1rpx solid #8a8a8a;
			font-size: 30rpx;

			.row_item {
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				text-align: center;

				&:nth-child(2) {
					border: 1rpx solid #8a8a8a;
					border-width: 0 1rpx 0 1rpx;
				}
			}

			&:last-child {
				border-top: none;
			}
		}

	}

	.life_card {
		height: 995rpx;
		width: 700rpx;
		margin: 5px auto;
		padding: 20rpx;
		box-shadow: 2px 2px 15px 2px #e3e3e3;
	}

	.watch {
		zoom: .7;
	}

	.face {
		position: relative;
		display: -webkit-box;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-pack: center;
		-ms-flex-pack: center;
		justify-content: center;
		-webkit-box-align: start;
		-ms-flex-align: start;
		align-items: flex-start;
		width: 500rpx;
		height: 500rpx;
		background: #eee;
		background-image: -webkit-linear-gradient(top left, #eee, #f5f5f5);
		background-image: linear-gradient(to bottom right, #eee, #f5f5f5);
		border-radius: 50%;
		padding: 20rpx;
		border: 20rpx solid #d9d9d9;
		box-shadow: 20rpx 20rpx 30rpx -10rpx rgba(0, 0, 0, 0.4), inset 10px 10px 20px rgba(0, 0, 0, 0.2);
		margin: 0 auto;
	}

	.face:after {
		display: block;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		content: "";
		border-radius: 50%;
		z-index: 9999;
		background-image: -webkit-linear-gradient(top left, rgba(255, 255, 255, 0) 0%, 59%, rgba(255, 255, 255, 0.7) 60%, rgba(255, 255, 255, 0) 80%), -webkit-linear-gradient(top left, rgba(255, 255, 255, 0) 0%, 30%, rgba(255, 255, 255, 0.3) 35%, rgba(255, 255, 255, 0.5) 40%, rgba(255, 255, 255, 0) 45%);
		background-image: linear-gradient(to bottom right, rgba(255, 255, 255, 0) 0%, 59%, rgba(255, 255, 255, 0.7) 60%, rgba(255, 255, 255, 0) 80%), linear-gradient(to bottom right, rgba(255, 255, 255, 0) 0%, 30%, rgba(255, 255, 255, 0.3) 35%, rgba(255, 255, 255, 0.5) 40%, rgba(255, 255, 255, 0) 45%);
	}

	.numbers {
		position: relative;
	}

	.number {
		position: absolute;
		height: 215rpx;
		-webkit-transform-origin: 0 100%;
		transform-origin: 0 100%;
		font-size: 28rpx;
	}

	.number:nth-child(1) {
		-webkit-transform: rotate(25deg);
		transform: rotate(25deg);
	}

	.number:nth-child(1) span {
		display: block;
		-webkit-transform: rotate(-25deg);
		transform: rotate(-25deg);
	}

	.number:nth-child(2) {
		-webkit-transform: rotate(55deg);
		transform: rotate(55deg);
	}

	.number:nth-child(2) span {
		display: block;
		-webkit-transform: rotate(-55deg);
		transform: rotate(-55deg);
	}

	.number:nth-child(3) {
		-webkit-transform: rotate(85deg);
		transform: rotate(85deg);
	}

	.number:nth-child(3) span {
		display: block;
		-webkit-transform: rotate(-85deg);
		transform: rotate(-85deg);
	}

	.number:nth-child(4) {
		-webkit-transform: rotate(115deg);
		transform: rotate(115deg);
	}

	.number:nth-child(4) span {
		display: block;
		-webkit-transform: rotate(-115deg);
		transform: rotate(-115deg);
	}

	.number:nth-child(5) {
		-webkit-transform: rotate(145deg);
		transform: rotate(145deg);
	}

	.number:nth-child(5) span {
		display: block;
		-webkit-transform: rotate(-145deg);
		transform: rotate(-145deg);
	}

	.number:nth-child(6) {
		-webkit-transform: rotate(175deg);
		transform: rotate(175deg);
	}

	.number:nth-child(6) span {
		display: block;
		-webkit-transform: rotate(-175deg);
		transform: rotate(-175deg);
	}

	.number:nth-child(7) {
		-webkit-transform: rotate(205deg);
		transform: rotate(205deg);
	}

	.number:nth-child(7) span {
		display: block;
		-webkit-transform: rotate(-205deg);
		transform: rotate(-205deg);
	}

	.number:nth-child(8) {
		-webkit-transform: rotate(235deg);
		transform: rotate(235deg);
	}

	.number:nth-child(8) span {
		display: block;
		-webkit-transform: rotate(-235deg);
		transform: rotate(-235deg);
	}

	.number:nth-child(9) {
		-webkit-transform: rotate(265deg);
		transform: rotate(265deg);
	}

	.number:nth-child(9) span {
		display: block;
		-webkit-transform: rotate(-265deg);
		transform: rotate(-265deg);
	}

	.number:nth-child(10) {
		-webkit-transform: rotate(295deg);
		transform: rotate(295deg);
	}

	.number:nth-child(10) span {
		display: block;
		-webkit-transform: rotate(-295deg);
		transform: rotate(-295deg);
	}

	.number:nth-child(11) {
		-webkit-transform: rotate(325deg);
		transform: rotate(325deg);
	}

	.number:nth-child(11) span {
		display: block;
		-webkit-transform: rotate(-325deg);
		transform: rotate(-325deg);
	}

	.number:nth-child(12) {
		-webkit-transform: rotate(355deg);
		transform: rotate(355deg);
	}

	.number:nth-child(12) span {
		display: block;
		-webkit-transform: rotate(-355deg);
		transform: rotate(-355deg);
	}

	.arms {
		position: absolute;
		top: 50%;
		left: 50%;
	}

	.arms:after {
		display: block;
		position: absolute;
		top: 50%;
		left: 50%;
		width: 26rpx;
		height: 26rpx;
		content: "";
		background: #ccc;
		border-radius: 50%;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		z-index: 999;
		box-shadow: 0 0 6rpx #545454;
	}

	.arm {
		transform-origin: center bottom;
		// transition: transform 1s linear;
	}

	.arm.arm-hour {
		position: absolute;
		bottom: 0;
		left: -4rpx;
		background-color: #000000;
		height: 80rpx;
		width: 10rpx;
	}

	.arm.arm-hour::before {
		content: '';
		position: absolute;
		top: -5px;
		width: 10rpx;
		height: 10rpx;
		background-color: #000000;
		transform: scaleY(4) rotateZ(45deg);
	}

	.arm.arm-minute {
		position: absolute;
		bottom: 0;
		left: -4rpx;
		background-color: #000000;
		height: 110rpx;
		width: 10rpx;
	}

	.arm.arm-minute::before {
		content: '';
		position: absolute;
		top: -5px;
		width: 10rpx;
		height: 10rpx;
		background-color: #000000;
		transform: scaleY(4) rotateZ(45deg);
	}

	.arm.arm-second {
		position: absolute;
		bottom: 0;
		left: -4rpx;
		background-color: #ff0000;
		height: 150rpx;
		width: 10rpx;
		transform-origin: bottom;
	}

	.arm.arm-second::before {
		content: '';
		position: absolute;
		top: -2px;
		width: 10rpx;
		height: 10rpx;
		background-color: #ff0000;
		transform: scaleY(4) rotateZ(45deg);
	}
</style>
